
//
//  UilityFile.swift
//  zpzk_shop
//
//  Created by Qingke on 16/5/21.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import Foundation
import UIKit
class UilityFile {
    
    //这段函数功能是返回文件存储位置，返回的是：APP的用户目录/形参   class +
    class func filePath(fileName: String) ->String {
        let path  = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
        let path0 = path[0]
        return "\(path0)/\(fileName)"               //空格在拼接字符串的时候 是多余一个字符
    }
    
    class func readFromFile(path: String) -> UIImage? {
        
        if  NSFileManager.defaultManager().fileExistsAtPath(path) {
            
            let data = NSFileManager.defaultManager().contentsAtPath(path)
            return UIImage(data: data!)
            
        }
        return nil
        
    }
    class func writeToFile(path:String,image: NSData) -> Bool {
        return image.writeToFile(path, atomically: true)
    }
}